<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
/*
	选择商品modal，通过访问此页面选择获取指定商品id
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
	//商品列表
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=$params=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	
	if($_RQ['workerid']){
		$params['id <>']=$_RQ['workerid'];
		$return['params']['workerid']=$_RQ['workerid'];
		$worker=pdo_get('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['workerid']));
		$workerids=json_decode($worker['workerids'],true);
		foreach($workerids as $wv){
			$ids[$wv['id']]=$wv['id'];
		}
	}
	if($_RQ['isfujia']){
		if($_RQ['storeid']){
			$params['storeid OR']='storeid='.$_RQ["storeid"].' or juese=5 or juese=6 or juese=7 or juese=8';
			$return['params']['storeid']=$_RQ['storeid'];
		}else{
			$params['juese']=array(1,3,4,5,6,7,8);
		}
		$return['params']['isfujia']=$_RQ['isfujia'];
	}else{
		if($_RQ['storeid']){
			$params['storeid']=$_RQ['storeid'];
			$return['params']['storeid']=$_RQ['storeid'];
		}
	}
	$fields=array('title');
	if($_RQ['title']){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	if($_RQ['juese']){
		$params['juese']=$_RQ['juese'];
		$return['params']['juese']=$_RQ['juese'];
	}
	$list=pdo_getslice('jy_yxw_worker',$params,array($pindex,$psize),$total,array('id','logo','title','juese','storeid'),'','id desc');
	if($list){
		foreach($list as &$item){
			$item['storetitle']=pdo_getcolumn('jy_yxw_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['storeid']),'title');
			if($_RQ['op']=='many'){
				$item['res']=array(
					'title'=>$item['title'],
					'id'=>$item['id'],
					'image'=>$item['logo']?$item['logo']:'../core/resource/images/nopic.jpg',
				);
			}else{
				$item['res']=$item['id'];
			}
			$item['isadd']=$ids[$item['id']]?1:0;
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array(
			'type'=>'list',
			'list'=>array('data'=>'list','del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
				array('name'=>'id','title'=>'员工id','type'=>'string'),
				array('name'=>'title','title'=>'员工名称','type'=>'string'),
				array('name'=>'storetitle','title'=>'门店','type'=>'string'),
				array('name'=>'juese','title'=>'角色','type'=>'radio','options'=>'user_juese'),
				//array('name'=>'isadd','title'=>'已选择？','type'=>'radio','options'=>'isadd'),
			),'action'=>array(
				array('type'=>'modal_result','name'=>'res','title_field'=>'title','title'=>'选取'),
			)),
			'search'=>array(
				array('name'=>'title','width'=>15,'title'=>'员工名称','type'=>'string'),
				array('name'=>'juese','width'=>15,'title'=>'角色','type'=>'radio','options'=>'user_juese2'),
			),
	);
	if(!$_RQ['storeid']){
		$return['htmls']['search'][]=array('name'=>'storeid','width'=>16,'title'=>'所属门店','type'=>'select','options'=>'stores');
	}
	$return['isadd']=array('未选择','已选择');
	$return['user_juese']=$this->user_juese;
	$return['user_juese2']=$this->user_juese2;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$return['stores']=$this->getall('store',$params,array('id','title'),'id');
	exi($return);

?>